// component/visitorsAll/com/visitor-item/visitor-item.js
import util from '../../../../utils/util.js'

const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
      value: {}
    }
  },

  options: {
    styleIsolation: 'apply-shared',
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _info: {}
  },

  observers: {
    info() {
      let info = {
        ...this.data.info
      }
      info.title = info.title2 || info.title
      try {
        info.isMe = info.unionid === app.globalData.sessionUser.extProps.wechatUnionid
      } catch (error) {}

      if (info.sign == "newHouse") {
        info.title = info.title + ' (新房)'
        info.imgId = info.first_picture_url
        info.detailInfo = `${info.average_price ? '均价' + info.average_price + '元/㎡' : '未填均价'}`

        this.setData({
          _info: info
        })
        return
      }

      info.createTime = info.createTime.slice(0, info.createTime.length - 3)
      if (info.buildingNum || info.unit == '' || info.roomNo) {
        var kong = '未填户型'
      } else {
        kong = `${info.buildingNum ? info.buildingNum + '栋-' : ''}
        ${info.unit ? info.unit + '单元' + '' : '无单元'}
        ${info.roomNo ? '-' + info.roomNo + '室' : ''}`
      }

      let titlesList = info.title.split("  ")
      info.title = titlesList[0]

      info.detailInfo = `
        ${info.total_prices && info.total_prices!=-1? (info.total_prices>=10000 ? info.total_prices/10000 + '万' : info.total_prices + '元'):'未填价格'}
        ${titlesList[1] || ""}
        ${info.build_size && info.build_size!=-1?info.build_size + '㎡':'未填面积'}
      `
      this.setData({
        _info: info
      })
    }
  },
  attached() {
    const that = this;
    that.setData({
      url: util.ImagesUrl
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    handleGoToCustomer() {
      wx.navigateTo({
        url: `/pages/customerDetailInfo/customerDetailInfo?userId=${this.data.info.anUserId}&unionid=${this.data.info.unionid}`
      })
    },

    handleGoRentalHouseDetail() {
      console.log(this.data.info);
      const houdelid = this.data.info.houDelId;
      const houseTypes = this.data.info.housetype;
      if (this.data.info.deleted) {
        wx.showToast({
          icon: 'none',
          title: '该房源被删除，无法查看',
        })
        return
      }
      if (this.data.info.sign == "newHouse") {
        wx.navigateTo({
          url: `/pages/newBuildinghouse/newRentalHouseDetail/newRentalHouseDetail?houdelid=${this.data.info.id}&isMay=true`
        })
      } else {
        wx.navigateTo({
          url: '/pages/house/RentalHouseDetail/RentalHouseDetail?houdelid=' + houdelid + "&from=1" + "&type=" + houseTypes,
        })
      }
    },

    hanldeCopyNickname() {
      this.triggerEvent("copyNickname", this.data.info)
    },

    onHideMe() {
      this.triggerEvent("hideMe", {
        userId: this.data.info.anUserId,
        unionid: this.data.info.unionid,
        target: 'TRACK'
      })
    }

  }
})